typedef struct SGNode{
	int bottom, top;
	int cover;
	struct SGNode *rchild, *lchild;
}SGNode, *SGTree;

void CreateSGTree(SGTree &T, int a, int b){
	T = (SGTree)malloc(sizeof(SGNode));
	T->bottom = a; T->top = b; T->cover = 0;
	if (b - a > 1){
		int mid = (a + b) / 2;
		GreateSGTree(T->lchild, a, mid);
		GreateSGTRee(T->rchild, mid, b);
	}
}
int SearchSGTree(SGTree T, int a, int b){
	if (T->bottom >= a && T->top <= b){
		return T->cover;
	}
	int vertex1, vertex2;
	mid = (T->bottom + T->top) / 2;
	if (a <= mid){
		vertex1 = SearchSGTree(T->rchild, a, b);
	}
	if (b >= mid){
		vertex2 = SearchSGTree(T->lchild, a, b);
	}
	return vertex2 > vertex1 ? vertex1 : vertex2;
}
void InsertSGTree(SGTree T, int a, int b){
	if (T->bottom >= a && T->top <= b){
		++T->cover;
	}
	if (T->bottom + 1 == T->top) return; 
	int mid = (T->bottom + T->top) / 2;
	if (mid >= a){
		InsertSGTree(T->rchild, a, b);
	}
	if (mid <= b){
		InsertSGTree(T->lchild, a, b);
	}
}
void DeleteSGTree(SGTree T, int a, int b){
	if (T->bottom >= a && T->top <= b){
		--T->cover;
	}
	if (T->bottom + 1 < T->top){
		int mid = (T->bottom + T->top) / 2;
		if (mid >= a){
			DeleteSGTree(T->rchild, a, b);
		}
		if (mid <= b){
			DeleteSGTree(T->lchild, a, b);
		}
	}
}